package com.sinosoft.ci.patch.yqscm;

import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;

class YQScmFileExtractJavaRow extends AbstractYQScmFileExtractRow{
	
	public YQScmFileExtractJavaRow(Row sheetRow){
		super(sheetRow);
	}
	
	/**
	 * 改行是否是个有效行
	 */
	public boolean isValid(){
		Cell fileCell = getFileCell();
		if(fileCell == null){
			return false;
		}
		
		String fileCellVal = fileCell.getStringCellValue();
		if(fileCellVal.trim().isEmpty()){
			return false;
		}
		if(fileCellVal.toLowerCase().endsWith(".class")){
			return false;
		}
		
		return true;
	}
	
	/**
	 * 获取源码条目文件后缀名
	 * 
	 * @return
	 */
	public String getEntryType(){
		Cell fileCell = getFileCell();
		if(null == fileCell){
			return null;
		}
		
		String fileName = fileCell.getStringCellValue().toLowerCase();
		if(fileName.indexOf(".") == -1){
			return "file";
		}
		String type = fileName.substring(fileName.lastIndexOf(".") + 1);
		return type.toLowerCase();
	}
	
	public String getSrcEntryPath(){
		if(!isValid()){
			return null;
		}
		Cell pathCell = getSheetRow().getCell(3);
		String pathCellStr = pathCell.getStringCellValue();
		
		Cell fileCell = getFileCell();
		String fileCellStr = fileCell.getStringCellValue();
		return pathCellStr + fileCellStr;
	}
	
	public String getFileName(){
		Cell cell = getFileCell();
		return cell == null ? null : cell.getStringCellValue();
	}
}
